package com.gscitysfy.cus.drain.modules.duty.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gscitysfy.cloudfrmwk.assistant.domain.Result;

import com.gscitysfy.cus.drain.modules.duty.entity.MoperDutyEtHoliday;
import com.gscitysfy.cus.drain.modules.duty.service.MoperDutyHolidayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author 钱小龙
 * @version 1.0.0
 * @ClassName MoperDutyHolidayController
 * @Description 值班节假日管理
 * @creatTime 2022-03-31 16:47:17
 */
@RestController
@RequestMapping("/Duty")
@Slf4j
public class MoperDutyHolidayController {

    @Resource
    private MoperDutyHolidayService moperDutyHolidayService;

    /**
     * 日历导入
     * @param file
     * @return
     */
    @PostMapping("/importHoliday")
    public Result importHoliday(MultipartFile file) {
        try{
            return Result.content(moperDutyHolidayService.importHoliday(file));
        }catch (Exception e){
            return Result.failure("上传失败!");
        }
    }


    /**
     * 修改工作日，非工作日
     * @param moperDutyEtHoliday
     * @param
     * @return
     */
    @PostMapping("saveHoliday")
    public Result<Integer> saveHoliday( MoperDutyEtHoliday moperDutyEtHoliday) throws ParseException {
        return Result.content(moperDutyHolidayService.saveHoliday(moperDutyEtHoliday));
    }


    /**
     * 查询工作日，非工作日
     * @param page
     * @param coamHoliday
     * @return
     */
    @GetMapping("/getHoliday")
    public Result getHoliday(Page<Map<String,Object>> page, String coamHoliday,String coamWorkdayFlag){
        return Result.content(moperDutyHolidayService.getHoliday(page,coamHoliday,coamWorkdayFlag));
    }


    /**
     * 自动排班
     * @param month
     * @param year
     */
    @RequestMapping("/autoDutyPlan")
    @ResponseBody
    public Result autoDutyPlan(String month,String year) {
        List<String> lsPerson = moperDutyHolidayService.saveAutoDutyPlan(month,year);
        String message = String.format("您好！%s年%s月排班情况已确定，请尽快进入系统查看排班情况！",year,month.replaceAll("^0*",""));
        moperDutyHolidayService.sendSms(lsPerson,message);
        return Result.content("");
    }
}
